<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input v-model="filters.search" placeholder="用户名或手机号"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="getUser">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<template>
			<el-table :data="users" highlight-current-row v-loading="loading" style="text-align: center;">
				<el-table-column  header-align="center" prop="id" label="用户ID"  width="120">
				</el-table-column>
				<el-table-column header-align="center" prop="username" label="昵称">
				</el-table-column>
				<el-table-column header-align="center" prop="phone" label="手机" width="200" >
				</el-table-column>
				<el-table-column header-align="center" prop="createTime" label="注册时间" width="250" >
				</el-table-column>
				<el-table-column header-align="center" prop="lastTime" label="最近登录" width="250" >
				</el-table-column>
				<el-table-column header-align="center" label="操作" width="150">
				<template scope="scope">
					<el-button size="small" @click="lookuserinfo(scope.$index, scope.row)">查看详情</el-button>
				</template>
			</el-table-column>
			</el-table>
		</template>
			<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="num" :total="total" style="float:right;">
			</el-pagination>
			<div class="all">总计<span class="total">{{total}}</span>条记录</div>
		</el-col>
	</section>

</template>
<script>
	import { sendData,cutString  } from "../../api/api";
	export default {
		data() {
			return {
				filters: {
					search: ''
				},
				loading: false,
				users: [
				],
				total: 0,
				page: 1,
				num:20
			}
		},
		methods: {
			//获取用户列表
			getUser: function () {
				let para = this.filters.search;
				let params=sendData({url: "user/find",msg: {search:para,order:2,pgNo:this.page,num:this.num}})
				this.loading = true;
				this.$http.get(params.baseURL,{params:params.params}).then(res=>{
					var res=cutString(res.bodyText)
					this.total=res.msg.total
					this.users = res.msg.userListRsps
					res.msg.userListRsps.map(function(v,i){
						v.createTime=v.createTime.slice(0,19)
						v.lastTime=v.lastTime.slice(0,19)
					})
					this.loading = false;
					console.log(res)
				})
			},
			// 分页请求
			handleCurrentChange(val) {
				this.page = val;
				this.getUser();
			},
			//查看详情界面
			lookuserinfo: function (index, row) {
				this.$router.push({  
            		path: '/userinfo',   
            		name: '用户详情',  
            		params: {   
                		id: row.id 
            		}   
        		})
			},

		},
		mounted() {
			this.getUser();
		}
	};

</script>

<style scoped>
.all{
	font-size: 16px;
	line-height: 32px;
	color: #666
}
.total{
		padding:0 5px;
		color: #52BAE9;
	}
</style>